<!DOCTYPE html>
<html>

<head>
    <meta name="layout" content="main"/>
    <g:set var="entityName" value="${message(code: 'jasperFile.label', default: 'JasperFile')}"/>
    <title>新增下载模板</title>
    <asset:stylesheet src="homer/vendor/jQuery-File-Upload/css/jquery.fileupload.css"/>
    <asset:stylesheet src="homer/vendor/blueimp-gallery/css/blueimp-gallery.min.css"/>

    <style>

    .img {
        width: 80px;
        height: 58px;
    }

    .fileupload table > tbody > tr > td {
        vertical-align: middle;
    }

    .fileupload-buttonbar button, .files button {
        margin-top: 2px;
    }
    </style>
</head>

<body class="fixed-navbar fixed-sidebar">
<div class="small-header">
    <div class="hpanel">
        <div class="panel-body">
            <div id="hbreadcrumb" class="pull-right">
                <ol class="hbreadcrumb breadcrumb">
                    <li>CINDATA PLS</li>
                    <li>
                        <g:link controller="jasperFile" action="index">下载模板管理</g:link>
                    </li>
                    <li class="active">
                        <span>新增下载模板</span>
                    </li>
                </ol>
            </div>

            <h2 class="font-light m-b-xs">
                下载模板管理-新增下载模板
            </h2>
        </div>
    </div>
</div>

<div class="content animate-panel">
    <div class="row">
        <div class="hpanel hblue">
            <div class="panel-heading">
                新增下载模板
            </div>

            <div class="panel-body form-horizontal">
                <g:form class="fileupload2 form-horizontal" action="uploadAvatar" method="post" enctype="multipart/form-data">
                    <div class="form-group">
                        <label class="col-md-3 control-label">下载模板</label>
                        <div class="col-md-8">
                            <div class="row fileupload-buttonbar">
                                <div class="col-lg-8">
                                    <span class="btn btn-info fileinput-button">
                                        <i class="glyphicon glyphicon-plus"></i>
                                        <span>选择文件</span>
                                        <input type="file" name="file" id="file" multiple>
                                    </span>
                                    <button type="submit" class="btn btn-primary start">
                                        <i class="glyphicon glyphicon-upload"></i>
                                        <span>开始上传</span>
                                    </button>
                                    <button type="reset" class="btn btn-warning cancel">
                                        <i class="glyphicon glyphicon-ban-circle"></i>
                                        <span>取消上传</span>
                                    </button>

                                    <span class="fileupload-process"></span>
                                </div>
                                <div class="col-lg-4 fileupload-progress fade">
                                    <div class="progress full progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100">
                                        <div class="progress-bar progress-bar-success" style="width:0%;"></div>
                                    </div>
                                    <div class="progress-extended">&nbsp;</div>
                                </div>
                            </div>
                            <p style="margin-top: 10px;">
                                <code>附件大小不能超过 5m,附件格式jrxml</code>
                            </p>
                            <table role="presentation" class="table table-striped"><tbody class="files"></tbody></table>
                        </div>
                    </div>
                </g:form>

                <div class="hr-line-dashed"></div>
                <g:form action="save" class="form-horizontal jasperFileForm">
                    <g:if test="${flash.message}">
                        <div class="message" role="status">${flash.message}</div>
                    </g:if>
                    <g:hasErrors bean="${this.jasperFile}">
                        <ul class="errors" role="alert">
                            <g:eachError bean="${this.jasperFile}" var="error">
                                <li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>>
                                    <g:message error="${error}"/>
                                </li>
                            </g:eachError>
                        </ul>
                    </g:hasErrors>

                    <div class="form-group">
                        <label class="col-md-3 control-label">下载模板名称</label>

                        <div class="col-md-3">
                            <g:textField name="name" value="${this.jasperFile?.name}" class="form-control"/>
                        </div>
                    </div>

                    <div class="hr-line-dashed"></div>

                    <div class="form-group">
                        <label class="col-md-3 control-label">模板描述</label>

                        <div class="col-md-3">
                            <g:textField name="description" value="${this.jasperFile?.description}" class="form-control"/>
                        </div>
                    </div>

                    <div class="hr-line-dashed"></div>

                    <div class="form-group">
                        <label class="col-md-3 control-label">关联组件</label>
                        <div class="col-md-3">
                            <g:select class="form-control" name="component.id" required="required" id="component" value="${this.jasperFile?.component?.id}" from="${com.cindata.Component.list()}"
                                    optionKey="id" optionValue="name" noSelection="${['': '请选择']}"></g:select>
                        </div>
                    </div>

                    <div class="hr-line-dashed"></div>

                    <div class="form-group">
                        <label class="col-md-3 control-label">模板路径</label>
                        <div class="col-md-3">
                            <g:textField name="fileUrl" id="fileUrl" value="${this.jasperFile?.fileUrl}" class="form-control" readOnly="true"/>
                        </div>
                    </div>

                    <div class="hr-line-dashed"></div>

                    <div class="form-group">
                        <div class="col-md-3 col-md-offset-3">
                            <g:submitButton class="btn btn-info" name="create" value="保存" id="submitButton" type="button"/>
                        </div>
                    </div>
                </g:form>
            </div>
        </div>
    </div>
</div>
<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
    <tr class="template-upload fade">
        %{--<td>
            <span class="preview"></span>
        </td>--}%
        <td>
            <p class="name">{%=file.name%}</p>
            <strong class="error text-danger"></strong>
        </td>
        <td>
            <p class="size">Processing...</p>
            <div class="progress full progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="progress-bar progress-bar-success" style="width:0%;"></div></div>
        </td>
        <td>
            {% if (!i && !o.options.autoUpload) { %}
                <button class="btn btn-primary start" disabled>
                    <i class="glyphicon glyphicon-upload"></i>
                    <span>上传</span>
                </button>
            {% } %}
            {% if (!i) { %}
                <button class="btn btn-warning cancel">
                    <i class="glyphicon glyphicon-ban-circle"></i>
                    <span>取消</span>
                </button>
            {% } %}
        </td>
    </tr>
{% } %}
</script>
<script id="template-download" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
    <tr class="template-download fade">
        <td>
            <span class="preview">
                {% if (file.thumbnailUrl) { %}
                    <a href="{%=file.thumbnailUrl%}" id="thumbnailUrl" title="{%=file.name%}" download="{%=file.name%}" data-gallery></a>
                {% } %}
            </span>
        </td>
        <td>
            <p class="name lightBoxGallery">
                {% if (file.url) { %}
                    <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" {%=file.thumbnailUrl?'data-gallery':''%}>{%=file.name%}</a>
                {% } else { %}
                    <span>{%=file.name%}</span>
                {% } %}
            </p>
            {% if (file.error) { %}
                <div><span class="label label-danger">Error</span>{%=file.error%}</div>
            {% } %}
        </td>
        <td>
            <span class="size">{%=file.size%}</span>
        </td>
        <td>
         {% if (file.error) { %}
          <button class="btn btn-success cancel">
                    <i class="glyphicon glyphicon-ban-circle"></i>
                    <span>取消上传</span>
                </button>
          {% } else { %}
               <button class="btn btn-success" type="button">
                    <i class="glyphicon glyphicon-ok"></i>
                    <span>上传成功</span>
               </button>
          {% } %}
        </td>
    </tr>
{% } %}

{%
    $("#fileUrl").val(o.files[0].fileUrl)
%}
</script>
<asset:javascript src="homer/vendor/jQuery-File-Upload/js/vendor/jquery.ui.widget.js"/>
<asset:javascript src="homer/vendor/jQuery-File-Upload/js/tmpl.min.js"/>
<asset:javascript src="homer/vendor/jQuery-File-Upload/js/load-image.all.min.js"/>
<asset:javascript src="homer/vendor/jQuery-File-Upload/js/canvas-to-blob.min.js"/>
<asset:javascript src="homer/vendor/jQuery-File-Upload/js/jquery.iframe-transport.js"/>
<asset:javascript src="homer/vendor/jQuery-File-Upload/js/jquery.fileupload.js"/>
<asset:javascript src="homer/vendor/jQuery-File-Upload/js/jquery.fileupload-process.js"/>
<asset:javascript src="homer/vendor/jQuery-File-Upload/js/jquery.fileupload-image.js"/>
<asset:javascript src="homer/vendor/jQuery-File-Upload/js/jquery.fileupload-validate.js"/>
<asset:javascript src="homer/vendor/jQuery-File-Upload/js/jquery.fileupload-ui.js"/>
<asset:javascript src="homer/vendor/jQuery-File-Upload/js/cors/jquery.xdr-transport.js"/>
<asset:javascript src="homer/vendor/blueimp-gallery/js/jquery.blueimp-gallery.min.js"/>


<script>
    $(function () 
    {
        $("#submitButton").click(function () 
        {
            $(".jasperFileForm").submit();
        });

        $('#file').change(function ()
        {
            var files = document.getElementById('file');
            $("#alert-danger").addClass('hide').text("")
            for (var i = 0; i < files.files.length; i++)
            {
                var file = files.files[i];
                if (file.size > 1024*1024*5) {
                    $("#alert-danger").removeClass('hide').text( file.name+ "图片大于5M，请修改后上传")
                    throw new Error("Something went badly wrong!");
                }
            }
        });

        $('.fileupload2').fileupload({
            messages: {
                maxNumberOfFiles: '文件个数不能超过1个',
            },
            maxFileSize: 2560000,
            maxNumberOfFiles: 1,
            acceptFileTypes: /(\.|\/)(jrxml)$/i
        });
    });
</script>

</body>
</html>